package com.xigua.JucOfBeautiful.chapterTen._10_1_CountDownLatch;

import java.util.concurrent.CountDownLatch;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/4/139:13
 */
public class JoinDwonLatch {

    private static volatile CountDownLatch countDownLatch = new CountDownLatch(2);

    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(()->{
            try {
                Thread.sleep(1000);
                System.out.println("child threadOne over");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                countDownLatch.countDown();
            }
        });

        Thread threadTwo = new Thread(()->{
            try {
                Thread.sleep(1000);
                System.out.println("child threadTwo over");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                countDownLatch.countDown();
            }
        });
        long start = System.currentTimeMillis();
        threadOne.start();
        threadTwo.start();
        System.out.println("wait all child over");
        countDownLatch.await();
        long end = System.currentTimeMillis();
        System.out.println(end-start);
        System.out.println("all child over");


    }

}
